package com.yld.car.receiver;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.ObjectOutputStream;

import com.yld.car.common.NetworkProgressUtils;
import com.yld.car.domain.ReflushStateInfo;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

public class MyAlarmReceiver extends BroadcastReceiver {

	@Override
	public void onReceive(final Context context, Intent intent) {

		NetworkProgressUtils utils = NetworkProgressUtils.getInstance();
		if (utils.getAPNType(context) == -1) {

			Toast.makeText(context, "网络已断开，请检查网络设置", Toast.LENGTH_SHORT).show();
			return;
		}

		new Thread(new Runnable() {

			@Override
			public void run() {

				// 序列化对象
				ReflushStateInfo rsi = new ReflushStateInfo();
				rsi.setReflush(true);
				ObjectOutputStream oot = null;
				try {
					oot = new ObjectOutputStream(context.openFileOutput(
							"reflush", Context.MODE_PRIVATE));
					oot.writeObject(rsi);
					System.out.println("onReceiver==>");
					// oot.close();
				} catch (FileNotFoundException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} finally {
					if (oot != null) {
						try {
							oot.close();
						} catch (IOException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					}

				}

			}

		}).start();

	}
}
